Listing 4. Code replacing call to FormsAuthentication.RedirectFromLoginPage

 
// authenticate user
if ((emailaddr.Value == DS_uidAndPwd.FieldValue("emailaddr",null)) &&
   (password.Value == DS_uidAndPwd.FieldValue("password",null))) 
{
   // The user has been authenticated. 
   // 1. Create the ticket.
   FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
      1,    // version
      Request.Form["emailaddr"],    // get the username (e-mail address) from the form
      DateTime.Now,    // issue time is now
      DateTime.Now.AddMinutes(30), // expires in 30 minutes
      false,    // cookie is not persistent
      "member");   // role assignment is stored in the UserData
   
   // 2. Create the cookie using the ticket.
   HttpCookie cookie = new HttpCookie(   FormsAuthentication.FormsCookieName,
   FormsAuthentication.Encrypt(ticket) );

   // 3. Attach the cookie to the outbound response.
   Response.Cookies.Add(cookie);

   // 4. Do the redirect.
   String returnUrl;
   if (Request.QueryString["ReturnURL"] == null)
   {
      returnUrl = "/members/index.aspx";
   }
   else
   {
      returnUrl = Request.QueryString["ReturnURL"];
   }
   Response.Redirect(returnUrl);
}
else 
{
   Msg.Text = "Invalid Credentials: Please try again";
}